#include "dh_math.h"



EXPORT_API float dh_math_fast_isqrt( const float& a )
{
	float ha = 0.5F * a;
	float ret;
	int i = *(int*)&a;
	i = 0x5F3759D5 - ( i >> 1 );
	ret = *(float*)&i;
	ret = ret * ( 1.5F - ha * ret * ret );
	return ret;	
}





//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DH_dh_vec2f METHODS
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


dh_vec2f::dh_vec2f( const float* v )
{
	x = v[0];
	y = v[1];
}

dh_vec2f::dh_vec2f( const dh_vec2f& v )
{
	x = v.x;
	y = v.y;
}

dh_vec2f::dh_vec2f( const float& nx, const float& ny )
{
	x = nx;
	y = ny;
}



float dh_vec2f::getLength()
{
	return 1.0F / ( dh_math_fast_isqrt( x * x + y * y ) );	
}



//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DH_VEC3F METHODS
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



float dh_vec3f::getLength() 
{
	return 1.0F / ( dh_math_fast_isqrt( x * x + y * y + z * z ) );
}

dh_vec3f::dh_vec3f()
{
	x = y = z = 0.0F;
}

dh_vec3f::dh_vec3f(const float* v)
{
	x = v[0];
	y = v[1];
	z = v[2];
}

dh_vec3f::dh_vec3f(const dh_vec3f& v)
{
	x = v.x;
	y = v.y;
	z = v.z;
}


dh_vec3f::dh_vec3f(const float& nx, const float& ny, const float& nz)
{
	x = nx;
	y = ny;
	z = nz;
}



//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DH_VEC4F METHODS 
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


dh_vec4f::dh_vec4f(const float* v)
{
	x = v[0];
	y = v[1];
	z = v[2];
	w = v[3];
}

dh_vec4f::dh_vec4f(const dh_vec4f& v)
{
	x = v.x;
	y = v.y;
	z = v.z;
	w = v.w;
}

dh_vec4f::dh_vec4f(const float& nx, const float& ny, const float& nz, const float& nw)
{
	x = nx;
	y = ny;
	z = nz;
	w = nw;
}


